﻿/*
    Project: IV:MP GUI Editor (http://code.google.com/p/ivmp-gui-editor)
    Code license: GNU Lesser GPL (http://www.gnu.org/copyleft/lesser.html) 
 */

using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
namespace IvmpEditor
{
    public class GUIButton : GUIElement
    {
        public new const string TYPE = "GUIButton";
        public override string GetTypeName() { return TYPE; }
        public override string GetDefaultVarName() { return "button"; }
        private new Button nativeControl;
        public new Button NativeControl { get { return this.nativeControl; } }

        public GUIButton(string _variableName)
        {
            variableName = _variableName;
            properties = new Dictionary<string, object>(25);
            MakeControl();
        }
        protected override void MakeControl()
        {            
            // Create a stylized native control of button
            nativeControl = new Button();
            base.nativeControl = this.nativeControl;
            moveControlAgent = new WpfMoveControlAgent(nativeControl);

            nativeControl.Style = GetBaseStyle();
            SetControlFont(nativeControl, "#tahoma-bold", 12, FontWeights.Black);
            nativeControl.Content = variableName;
        }
        public override void SetText(string newTxt, bool native)
        {
            base.SetText(newTxt, native);
            if (native && nativeControl != null)
                nativeControl.Content = newTxt;
        }
        public override void SyncFromNative()
        {
            base.SyncFromNative();
        }
        public override void SyncToNative()
        {
            base.SyncToNative();
        }
        public override string GetSQCode(ref SquirrelCodeStack sq)
        {
            sq.wSet(null, variableName, TYPE + "()", true);

            WriteElementCommonCode(ref sq, new Point(1.85, -1.3), variableName);

            return variableName;
        }
        public override Style GetBaseStyle()
        {
            return App.Current.FindResource("CEGUI_Button") as Style;
        }
    }
}
